
/*
 * Copyright (C) 2009 Archie L. Cobbs. All rights reserved.
 *
 * $Id: XMLFloatField.java 187 2009-11-12 18:27:01Z archie.cobbs $
 */

package org.dellroad.sidekar.xml;

import org.dellroad.sidekar.FloatField;

/**
 * Container for a {@link FloatField}'s value during the Sidekar XML import/export process.
 */
class XMLFloatField extends XMLAtomicField<Float> {

    private float value;

    // Used during unmarshalling
    private XMLFloatField(XMLItem xmlItem) {
        super(xmlItem);
    }

    // Used during unmarshalling
    private XMLFloatField(XMLField xmlField) {
        super(xmlField);
    }

    // Used during marshalling
    public XMLFloatField(String name, float value) {
        super(name);
        this.value = value;
    }

    // Used during unmarshalling
    @Override
    public Float getObjectValue() {
        return this.value;
    }

    // Used during marshalling
    @Override
    public boolean hasDefaultValue() {
        return this.value == 0.0f;
    }

    // Used during unmarshalling
    public static XMLFloatField newInstance(Object obj) {
        return obj instanceof XMLItem ? new XMLFloatField((XMLItem)obj) : new XMLFloatField((XMLField)obj);
    }
}

